package io.cici.cc.mybatis.plus.core.tagHandler;

import io.cici.cc.mybatis.lite.sql_source.scripting.tag.IfTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.MixedTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.Tag;
import io.cici.cc.mybatis.plus.core.MybatisXMLScriptBuilder;

import java.util.List;

public class IfHandler implements TagHandler {
    private final MybatisXMLScriptBuilder mybatisXMLScriptBuilder;

    public IfHandler(MybatisXMLScriptBuilder mybatisXMLScriptBuilder) {
        this.mybatisXMLScriptBuilder = mybatisXMLScriptBuilder;
        // Prevent Synthetic Access
    }

    @Override
    public void handleNode(io.cici.cc.mybatis.lite.parse.Node nodeToHandle, List<Tag> targetTagList) {
        MixedTag mixedTag = mybatisXMLScriptBuilder.parseDynamicTags(nodeToHandle);
        String test = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("test"));
        IfTag ifTag = new IfTag(test, mixedTag);
        targetTagList.add(ifTag);
    }
}
